package com.wy.config;


import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: wy
 * @Date:2019/10/30 18:36
 */
@Configuration
public class ProducerConfig {

    //交换机名称
     public static final  String ITEM_TOPIC_EXCHANGE="item_topic_exchange";
    //队列名称
     public static final String ITEM_QUEUE="item_queue";
    //声明交换机
    @Bean("itemTopicExchange")
     public Exchange exchange(){
           return ExchangeBuilder.topicExchange(ITEM_TOPIC_EXCHANGE).durable(true).build();
     }
    //声明队列
         @Bean("itemQueue")
      public Queue queue(){
          return QueueBuilder.durable(ITEM_QUEUE).build();
      }
    //绑定交换机和队列
       @Bean
    public Binding itemQueueExchange(@Qualifier("itemQueue") Queue queue,@Qualifier("itemTopicExchange") Exchange exchange){

         return  BindingBuilder.bind(queue).to(exchange).with("item.*").noargs();
    }

}
